/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pfc.modelocg;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;
import pfc.modeloer.ERAttrib;
import pfc.modeloer.EREntity;

/**
 *
 * @author xandru
 */
public class CGForm {

    String _name;
    EREntity _entity;
    ArrayList<CGField> _fields = new ArrayList<CGField>();
    //HashMap<String,String> _props = new HashMap<String,String>();
    private String _entityName;
    FormType _type;
    private Integer _numberOfLines=10;
    private Integer _numberOfColumns=1;

    public void addField(CGField field) {
        this._fields.add(field);
    }

    public CGField getField(String campo) {
        CGField f=null;
        for (CGField f1: this._fields)
            if (f1.getName().equals(campo))
            {
                f = f1;
                break;
            }
        return f;
    }

    public void setNumberOfLines(int parseInt) {
        this._numberOfLines = parseInt;
    }

    public void setNumberOfColumns(int parseInt) {
        this._numberOfColumns = parseInt;
    }

    public Integer getNumberOfColumns() {
        return _numberOfColumns;
    }

    public Integer getNumberOfLines() {
        return _numberOfLines;
    }


    public static enum FormType {EditForm, LinesForm, SearchForm, UNKNOWN};


    private CGForm(){}

    CGForm(EREntity e, FormType tipo) {
        _name = e.getName()+tipo;
        _entity = e;
        _type = tipo;

/*
        _props.put("generateEditForm", Boolean.toString(true));
        _props.put("generateLinesForm", Boolean.toString(true));
        _props.put("generateSearchForm",Boolean.toString(true));
        _props.put("generatedLinkedForms", Boolean.toString(true));
*/

        createFromEntity();
    }

    public static CGForm createCGForm()
    {
        CGForm c = new CGForm();
        c._type = FormType.UNKNOWN;
        return c;
    }

    public EREntity getEntity() {
        return _entity;
    }

    public void setEntity(EREntity _entity) {
        this._entity = _entity;
    }

    public ArrayList<CGField> getFields() {
        return _fields;
    }

    public void setFields(ArrayList<CGField> _fields) {
        this._fields = _fields;
    }

    public String getName() {
        return _name;
    }

    public void setName(String _name) {
        this._name = _name;
    }




    private void createFromEntity() {
        _entityName = _entity.getName();
        for (ERAttrib a: _entity.getAttribs())
        {
            CGField f = new CGField(a);
            if (this._type==FormType.LinesForm)
                f.setEditable(false);
            this._fields.add(f);
        }

    }

/*
    public String[] getPropertyList ()
    {
        return _props.keySet().toArray(new String[_props.size()]);
    }

    public String getProperty (String key)
    {
        return _props.get(key);
    }
*/
    
    void setEntityName(String attributeValue) {
        this._entityName = attributeValue;
    }

    public String getEntityName() {
        return this._entityName;
    }

    public FormType getType() {
        return _type;
    }

    public void setType(FormType _type) {
        this._type = _type;
        if (this._type!=FormType.LinesForm)
            return;

        for (CGField f: this._fields)
                f.setEditable(false);


    }




}
